Skip to content

JS: fix npmPublish skip detection that always reported "already published"#7570

Merged
greg-at-moderne merged 2 commits intomainfrom
tim/fix-npm-publish-skip-logic
May 5, 2026
Merged

JS: fix npmPublish skip detection that always reported "already published"#7570
greg-at-moderne merged 2 commits intomainfrom
tim/fix-npm-publish-skip-logic

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 5, 2026

Summary

  • PR JS: skip npm publish when snapshot version already exists #7552 added an onlyIf block on npmPublish that runs npm view @openrewrite/rewrite@<version> version and skips publishing when the captured output contains the version string. With redirectErrorStream(true), npm's 404 error message also contains the requested version:
npm error 404 No match found for version 8.82.0-20260505-090457
npm error 404
npm error 404  The requested resource '@openrewrite/rewrite@8.82.0-20260505-090457' could not be found …

So output.contains(versionToCheck) matches on every miss, and the daily snapshot publish has been silently skipped since 2026-05-02. Maven snapshots keep ticking forward with each new commit timestamp (currently at 8.82.0-20260505-090457), but the npm prerelease tag is still frozen at 8.82.0-20260502-150813.

Downstream impact

Consumers spawn the JS RPC subprocess via:

npx --package=@openrewrite/rewrite@<version-from-jar> rewrite-rpc …

where <version-from-jar> is read from META-INF/rewrite-javascript-version.txt. Once the npm/Maven versions diverge, that command fails with ETARGET and the subprocess exits 1, surfacing in downstream tests as RPC process shut down early with exit code 1 or Expected Content-Length header but received ''.

This is breaking the rewrite-static-analysis scheduled CI on every full test run since 2026-05-04 (e.g. run 25335376932). Tests AnnotateNullableMethodsTest.typescriptCode and RemoveUnusedLocalVariablesTest$Typescript.noChange reproduce the failure locally on macOS once the local npm link is removed.

Fix

Switch the skip check to use npm view's exit code (and verify the version appears on its own line in stdout) so we only skip publishing when the version is genuinely already published. Drafting for review and to validate against the next scheduled CI run.

Test plan

  • Manual: run npm view @openrewrite/rewrite@<existing> version and <nonexistent> and confirm the new logic agrees with reality
  • Confirm next scheduled CI publishes a new prerelease that matches the Maven snapshot's version stamp
  • Confirm rewrite-static-analysis scheduled CI returns to green

…shed"

PR #7552 added an `onlyIf` block that ran `npm view @openrewrite/rewrite@<version>
version` and skipped publishing if the captured output contained the version
string. With `redirectErrorStream(true)`, npm's 404 error message also contains
the requested version (e.g. "The requested resource '@openrewrite/rewrite@<version>'
could not be found"), so the contains-check matched on every miss and silently
skipped npm publish for any newly-stamped snapshot.

The npm prerelease tag has been frozen at 8.82.0-20260502-150813 since then,
while Maven snapshots continue to advance with the latest commit timestamp.
Downstream consumers that try to spawn the JS RPC subprocess via
`npx --package=@openrewrite/rewrite@<jar-version> rewrite-rpc` then fail with
ETARGET because the version baked into the JAR's resource is not on npm,
breaking CI in repositories like rewrite-static-analysis.

Switch the check to use `npm view`'s exit code (and verify the version appears
on its own line in stdout) so we only skip when the version is genuinely
already published.
@timtebeek
Copy link
Copy Markdown
Member Author

@greg-at-moderne since you reviewed #7552 — small follow-up to fix the skip detection. Drafting until the next scheduled run lands so we can confirm npm and Maven versions re-align.

Comment thread rewrite-javascript/build.gradle.kts Outdated
process.waitFor()
val output = process.inputStream.bufferedReader().readText().trim()
val alreadyPublished = output.contains(versionToCheck)
val alreadyPublished = process.waitFor() == 0 && output.lines().any { it.trim() == versionToCheck }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be contains instead of ==?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Applied just now; ready to merge if you agree (feel free to push the button as I'm out for a bit here).

Address review feedback: with the exit-code gate in place, the merged
stderr/stdout 404 case can no longer reach this check, so a simple
contains is enough and is more forgiving of minor npm view output
formatting differences.
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite May 5, 2026
@greg-at-moderne greg-at-moderne merged commit 0a80d89 into main May 5, 2026
1 check passed
@greg-at-moderne greg-at-moderne deleted the tim/fix-npm-publish-skip-logic branch May 5, 2026 12:11
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants